package com.sanpu.kxe.business.main.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.common.enums.Option;
import com.sanpu.kxe.module.roundview.RoundTextView;

import butterknife.ButterKnife;

/**
 * Description：首页应用区
 * Created by 薛勇军 on 2018/8/3.
 */

public class HomeApplicationAdapter extends BaseAdapter {

    private Context mContext;

    private boolean isSameDay;

    private Option[] mOptions = new Option[]{
//            new Option(R.drawable.ic_index_point, "卡积分兑换"),
            new Option(R.drawable.ic_index_advice, "了难中心"),
            new Option(R.drawable.ic_index_upgrade, "升级会员"),
            new Option(R.drawable.ic_index_user_sign, "签到中心"),
            new Option(R.drawable.ic_index_pos, "0元购机"),
            new Option(R.drawable.ic_index_oversea_shopping, "境外购"),
            new Option(R.drawable.ic_index_more, "更多"),
    };

    public HomeApplicationAdapter(Context context) {
        this.mContext = context;
    }

    public void setNotifyDataChanged(boolean isSameDay) {
        this.isSameDay = isSameDay;
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (mOptions ==null) {
            return 0;
        }
        return mOptions.length;
    }

    @Override
    public Option getItem(int position) {
        return mOptions[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_option_home, null);
        }
        ImageView icon = ButterKnife.findById(convertView, R.id.icon);
        TextView title = ButterKnife.findById(convertView, R.id.title);
        RoundTextView badge = ButterKnife.findById(convertView, R.id.badge);
        View flag = ButterKnife.findById(convertView, R.id.flag);

        Option option = getItem(position);
        if (option != null) {
            icon.setImageResource(option.getIcon());
            title.setText(option.getTitle());
//            if (option.getIcon() == R.drawable.ic_index_advice) {
//                flag.setVisibility(View.VISIBLE);
//            } else {
//                flag.setVisibility(View.GONE);
//            }
            if (option.getIcon() == R.drawable.ic_index_user_sign && !isSameDay) {
                badge.setVisibility(View.VISIBLE);
            } else {
                badge.setVisibility(View.GONE);
            }
        }
        return convertView;
    }
}
